package com.easyfun.healthmagicbox.ormlite;

public enum ServerResponseCode {
	WAITING(-1,"WAITING"), SUCCESS (0,"OK"), FAILED (1,"FAILED"), 
    NOMORE (2,"NO MORE"), NOCONNECTION(3, "NO CONNECTION"), UNKNOWN (100,"UNKNOWN");
	
	// 
    private int nCode ;
    private String nName ;
    // 
    private ServerResponseCode( int _nCode, String name) {
        this . nCode = _nCode;
        this.nName = name;
    }

    @Override
    public String toString() {
        return nName;
    }
    
    public Integer toInteger() {
        return nCode;
    }
    
    public static ServerResponseCode parseOf(String str)
    {
    	int begin = 0;
    	int end = str.length();

    	boolean changedflag = false;
    	if (str.charAt(0)=='\"')
    	{
    		begin = 1;
    		changedflag = true;
    	}
    	if (str.charAt(end - 1)=='\"')
    	{
    		end = end - 1;
    		changedflag = true;
    	}
		if (changedflag)
    		str = str.substring(begin,end);
    	
    	for (ServerResponseCode response: ServerResponseCode.values())
    	{
    		if (response.toString().equals(str))
    			return response;
    	}
    	return ServerResponseCode.UNKNOWN;
    }
}
